/**
 * @file
 * @author dousha
 * @date 2020/11/30.
 */

#ifndef CRYPTSTICK_SAVED_SECRETS_H
#define CRYPTSTICK_SAVED_SECRETS_H

#include <stdint.h>

typedef struct {
	char name[16];
	uint16_t pos;
	uint16_t length;
	uint16_t year;
	uint16_t month;
	uint16_t day;
	uint16_t hour;
	uint16_t minute;
	uint16_t metadata;
} __attribute__((packed)) secret_index;

#define SECRET_INDEX_TABLE_SIZE 32

#define SECRET_META_USED 0x4000u
#define SECRET_META_HEX 0x8000u

extern uint8_t secret_unlock(uint32_t);

extern uint8_t secret_allocate();

extern void secret_generate(uint32_t);

extern void secret_init();

extern void secret_touch(uint8_t, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t);

extern void secret_get_prepare(uint8_t);

extern void secret_set_prepare();

extern uint8_t secret_read_page(uint8_t[32]);

extern uint8_t secret_write_page(const uint8_t[32]);

extern uint8_t secret_seek(const char *, uint8_t);

extern volatile secret_index *secret_current_get();

extern void secret_index_load(uint16_t);

extern void secret_index_save(uint16_t);

extern uint8_t secret_index_is_valid(uint16_t);

extern void secret_set_time(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t);

extern const uint8_t *secret_master_secret();

#endif //CRYPTSTICK_SAVED_SECRETS_H
